Skip to content

Add preview metadata to buffered tail traces#6375

Open
Ankcorn wants to merge 3 commits intocloudflare:mainfrom
Ankcorn:tankcorn/preview-observability
Open

Add preview metadata to buffered tail traces#6375
Ankcorn wants to merge 3 commits intocloudflare:mainfrom
Ankcorn:tankcorn/preview-observability

Conversation

@Ankcorn
Copy link

@Ankcorn Ankcorn commented Mar 20, 2026

Summary

Add preview metadata to buffered tail traces.

This exposes:

  trace.preview = { id, slug, name }

to classic/buffered tail workers.

Why Why

edgeworker needs to surface pipeline-level preview identity in classic tail worker
observability.

That requires workerd to support carrying preview metadata through the buffered trace path;
otherwise classic tail workers only receive traces without any preview context.

Changes

  • add top-level preview field to rpc::Trace
  • add in-memory TracePreview
  • serialize / deserialize it through io/trace.*
  • expose it on the JS buffered tail trace API as trace.preview
  • add a focused round-trip trace test

Notes

This only adds the workerd support layer. The corresponding edgeworker change is what populates
this field from pipeline preview metadata.

@Ankcorn Ankcorn requested review from a team as code owners March 20, 2026 17:18
@github-actions
Copy link

github-actions bot commented Mar 20, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.


TraceEventInfo::TraceItem::TraceItem(rpc::Trace::TraceEventInfo::TraceItem::Reader reader)
: scriptName(kj::str(reader.getScriptName())) {}
: scriptName(reader.hasScriptName() ? kj::Maybe<kj::String>(kj::str(reader.getScriptName()))
Copy link
Author

@Ankcorn Ankcorn Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opencode drive by changed this because it thinks the old implementation has a bug...

IMO seems suss and I'm going to revert this line but hello @danlapid I just wanted to flag it to you incase opencode smarter than me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's right. The previous code didn't preserve the emptiness of the scriptName capnp field during a serialization round trip (which seems to be used by TraceCustomEvent::sendRpc method for sending traces over an RPC interface).

I think this matters in practice too since the worker may be deployed without a script name in some cases. I suspect the failures you're seeing on the internal build are due to this changing behaviour in cases where script name is empty. It likely results in a trace item having a null scriptName instead of empty string. We might need to put the change behind a compatibility date if so, because even though it's a bug fix it's a change in API behaviour.

jsg::Optional<ScriptVersion> getScriptVersion();
jsg::Optional<kj::StringPtr> getDispatchNamespace();
jsg::Optional<kj::Array<kj::StringPtr>> getScriptTags();
jsg::Optional<jsg::Dict<kj::String>> getPreview();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this a JSG struct instead of a JSG dict. I think dicts are meant to be for when you don't know the keys at compile time. See getScriptVersion for inspiration.

@Ankcorn Ankcorn force-pushed the tankcorn/preview-observability branch from fb12ef3 to 4dddab3 Compare March 25, 2026 09:57
@Ankcorn
Copy link
Author

Ankcorn commented Mar 25, 2026

I have read the CLA Document and I hereby sign the CLA

@Ankcorn
Copy link
Author

Ankcorn commented Mar 25, 2026

recheck

github-actions bot added a commit that referenced this pull request Mar 25, 2026
@Ankcorn Ankcorn requested a review from jp4a50 March 25, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants